<?php
/*
 *   CakePHP PagSeguro Plugin
 *   Copyright (C) 2009  Yuri Pereira Teixeira - (blog.yuriteixeira.com)
 *   Based on Felipe Theodoro Gonçalves's original work (http://code.google.com/p/pagseguro/)
 *
 *   This program is free software: you can redistribute it and/or modify
 *	 it under the terms of the GNU General Public License as published by
 *   the Free Software Foundation, either version 3 of the License, or
 *   (at your option) any later version.
 *
 *   This program is distributed in the hope that it will be useful,
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *   GNU General Public License for more details.
 *
 *   You should have received a copy of the GNU General Public License
 *   along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 */
class formpgHelper extends AppHelper {

	public $helpers = array('Form');

	/**
	 * Cria o form padrão
	 * @return String
	 */
	public function create($encoding = ''){
		$out = '<form action="https://pagseguro.uol.com.br/checkout/checkout.jhtml" method="post">';
		
		if ($encoding) {
			$out .= '<input type="hidden" name="encoding" value="' . $encoding . '" />';
		}
		
		return $this->output($out);
	}

	/**
	 * Cria os hidden com os dados necessários para envio das informações
	 * @param array $data = null
	 * @return String
	 */
	public function hidden($data = null){
		$out = null;
		if(is_array($data)){
			foreach($data as $key => $value){
				$out .= '<input type="hidden" name="' . $key . '" value="' . $value . '">';
			}
		}
		return $this->output($out);
	}

	/**
	 * Cria o button submit
	 * @param array $params = array
	 * @return String
	 */
	public function submit($params = array()){
		$out = null;
		if(empty($params)){
			$out = '<input type="image" value="submit" src="https://p.simg.uol.com.br/out/pagseguro/i/botoes/carrinhoproprio/btnfinalizaBR.jpg" alt="Pague com PagSeguro - é rápido, grátis e seguro!">';
		}elseif(isset($params['img'])){
			$out = '<input type="image" value="submit" src="https://p.simg.uol.com.br/out/pagseguro/i/botoes/carrinhoproprio/' . $params['img'] . '" alt="Pague com PagSeguro - é rápido, grátis e seguro!">';
		}
		return $this->output($out);
	}

	/**
	 * Finaliza o form
	 * @return String
	 */
	public function end(){
		$out = '</form>';
		return $this->output($out);
	}
}